<?php

/**
 * makes coloring of all graphs by Brelaz's algorithm
 */

require_once(dirname(__FILE__) . '/include.php');

$query = 'SELECT id FROM graph';
$graphs = $GLOBALS['db']->fetchAll($query);

foreach ($graphs as $gr) {
	for ($i = 0; $i < 5; $i++) {
		$graph = new DBGraph($gr['id']);
		$start = microtime(true);
		$brelaz = new Brelaz();
		$brelaz->coloring($graph);
		$end = microtime(true);
	
		$params = array(
			'algorithm' => 1,
			'graph' => $gr['id'],
			'found_chromatic_number' => $graph->getColorsCount(),
			'duration' => $end - $start,
			'coloring' => $graph->getSerializedColors(),
		);
		
		if ($graph->check()) {
			$params['good'] = 1;
		}
	
		$GLOBALS['db']->insert('chromatic_number', $params);
	}
}

?>